//
//  BasNavViewController.swift
//  wbxm
//
//  Created by apple on 15/12/23.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class BasNavViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置返回手势
        self.interactivePopGestureRecognizer?.delegate = self

    
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //viewController 是将要跳转的页面
        
        //自定义返回按钮
        //一旦自定义反悔按钮 导航视图控制器的返回手势的协议对象 会重置
        if childViewControllers.count != 0 {
            let btn = UIButton(title: "返回", backImageName: nil, fontSize: 14, color: UIColor.lightGrayColor(), imageName: "navigationbar_back_withtext")
            btn.addTarget(self, action: "back", forControlEvents: UIControlEvents.TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
            viewController.hidesBottomBarWhenPushed = true

        }

        
        //调用父类的跳转函数 这句话执行后 才会真正的执行页面的跳转
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back() {
        //self就可以直接使用
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        print("你若安好,便是晴天")
        
        
        return childViewControllers.count != 1
    }
 
}
